#-------------------------------------------------------------------------------
# Name:        Label
# Purpose:
#
# Author:      Theo
#
# Created:     25/01/2012
# Copyright:   (c) Monxcleyr Productions 2012
# Licence:     GPL v3
#-------------------------------------------------------------------------------
#!/usr/bin/env python

import pygame

class Label:
  def __init__(self,screen,text,pos,align,font,font_col,bg_col=(255,0,255)):
    self.text = text
    self.font = font
    self.font_col = font_col
    self.bg_col = bg_col
    self.pos = pos
    self.align = align
    self.screen = screen

  def draw(self):

    """ Draws the label to the screen.

    Label.draw() -> rect

    Returns rect containing teh affected pixels. (like pygame.Surface.blit()) """

    self.width = 0
    self.height = self.font.size(self.text[0])[1]
    for i in range(0, len(self.text)):
      if self.height > self.font.size(self.text[i])[1]:
        self.height = self.font.size(self.text[i])[1]
    self.width = self.width + self.font.size(self.text)[0]

    tempsurf = self.font.render(self.text,True,self.font_col)
    rect = (0,0,0,0)
    if self.align == 'left':
      #pygame.draw.rect(self.screen,self.bg_col,pygame.Rect(self.pos,(self.width,self.height)))
      rect = self.screen.blit(tempsurf,self.pos)

    elif self.align == 'right':
      rect = self.screen.blit(tempsurf,(self.pos[0] - self.width, self.pos[1]))

    elif self.align == 'center':
      rect = self.screen.blit(tempsurf,(self.pos[0] - (self.width / 2), self.pos[1]))

    return rect


  def getText(self):
    return self.text

  def setText(self, newText):
    self.text = newText
